package com.crrc.yzt.demo.fragment

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.crrc.yzt.demo.blue.R
import com.crrc.yzt.demo.activity.CarDateListActivity
import com.crrc.yzt.demo.activity.CarDetailActivity
import com.crrc.yzt.demo.activity.DateReviewActivity
import com.crrc.yzt.demo.activity.EnergyActivity
import com.crrc.yzt.demo.activity.ErrorDataListActivity
import com.crrc.yzt.demo.activity.TelnetUpdateActivity
import com.crrc.yzt.demo.activity.ValueActivity
import com.crrc.yzt.demo.activity.ValueActivity3
import com.crrc.yzt.demo.blue.databinding.FragmentCarHomeBinding


/**
 */
class CarHomeFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val binding = FragmentCarHomeBinding.inflate(layoutInflater)

        binding.itemLayout0.setOnClickListener(ItemClick(activity,0,resources.getString(R.string.item_4)))
        binding.itemLayout1.setOnClickListener(ItemClick(activity,1,resources.getString(R.string.item_5)))
//        binding.itemLayout2.setOnClickListener(ItemClick(activity,2,resources.getString(R.string.item_6)))
        binding.itemLayout4.setOnClickListener(ItemClick(activity,4,resources.getString(R.string.item_7)))
        binding.itemLayout9.setOnClickListener(ItemClick(activity,9,resources.getString(R.string.item_8)))
        binding.itemLayout10.setOnClickListener(ItemClick(activity,10,resources.getString(R.string.item_9)))


        return binding.root
    }





    companion object {

        @JvmStatic
        fun newInstance() =
            CarHomeFragment().apply {

            }
    }
}


class ItemClick(val activity:Activity?,val index:Int,val title:String):View.OnClickListener{
    override fun onClick(v: View?) {

        when(index){
            0->{
                activity?.startActivity(Intent(activity, CarDetailActivity::class.java))
            }
            3-> {
                activity?.startActivity(Intent(activity, ValueActivity3::class.java).apply {
                    putExtra("title", title)
                    putExtra("index", index)
                })
            }
            9->{
                activity?.startActivity(Intent(activity, CarDateListActivity::class.java).apply {
                })
            }
            10->{
                activity?.startActivity(Intent(activity, DateReviewActivity::class.java).apply {
                })
            }
            else->{
                activity?.startActivity(Intent(activity, ValueActivity::class.java).apply {
                    putExtra("title",title)
                    putExtra("index",index)
                })
            }
        }

    }

}